package com.back.mapper;

import com.back.entity.Log;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LogDao {
    //添加
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id", before = false, resultType = int.class)
    @Insert("insert into log(url,name,ip,status,msg) values(#{url},#{name},#{ip},#{status},#{msg})")
    void add(Log log);

    //查询
    @Select("select * from log order by time desc limit #{current},#{pagesize}")
    List<Log> query(@Param("current") int current, @Param("pagesize") int pagesize);

    //查询
    @Select("select * from log where id = #{id}")
    Log queryById(@Param("id") int id);

    //查询
    @Select("select * from log where id = (select max(id) from log where url like '/news/%')")
    Log queryById2(int id);

    //查询：只返回获取唯一标识相关日志
    @Select("select * from log where url like '/news/%' order by time desc limit #{current},#{pagesize}")
    List<Log> queryByUid(@Param("current") int current, @Param("pagesize") int pagesize);

    //查询：只返回获取唯一标识相关日志
    @Select("select count(*) from log where url like '/news/%'")
    int queryNumOfUid();

    //计数
    @Select("select count(*) from log")
    int totalnum();

    // 查询同一人在同一页面的几分钟内的最新ID
    @Select("select max(id) from log where name = #{username} and url = #{url} and time between date_sub(now(),interval #{time} minute) and now()")
    Integer queryId(@Param("username") String username, @Param("url") String url, @Param("time") int time);


}
